﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DemoGrid.aspx.cs" Inherits="WebApplication2.DemoGrid" %>


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="Stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/redmond/jquery-ui.css" />
    <script src="js/jquery.js"></script>
        <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            if ($('#grvStudentDetails_btnadd').click) {
                $('#grvStudentDetails_txtcust_add').focus();
            }
            $('#grvStudentDetails_txtcust_add').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13' || keycode == '108') {
                    if ($('#grvStudentDetails_txtcust_add').val() == "")
                        $('#grvStudentDetails_txtcust_add').focus();
                    else
                        $('#grvStudentDetails_txtcustname_add').focus();
                    return false;
                }
            });
            $('#grvStudentDetails_txtcustname_add').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13' || keycode == '108') {
                    if ($('#grvStudentDetails_txtcustname_add').val() == "")
                        $('#grvStudentDetails_txtcustname_add').focus();
                    else
                        $('#grvStudentDetails_txtaddress_add').focus();
                    return false;
                }

            });
            $('#grvStudentDetails_txtaddress_add').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13' || keycode == '108') {
                    if ($('#grvStudentDetails_txtaddress_add').val() == "")
                        $('#grvStudentDetails_txtaddress_add').focus();
                    else
                        $('#grvStudentDetails_dlprovince_add').focus();
                    return false;
                }

            });
            $('#grvStudentDetails_dlprovince_add').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13' || keycode == '108') {
                    if ($('#grvStudentDetails_dlprovince_add').val() == "")
                        $('#grvStudentDetails_dlprovince_add').focus();
                    else
                        $('#grvStudentDetails_dltown_add').focus();
                    return false;
                }

            });
            $('#grvStudentDetails_dltown_add').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13' || keycode == '108') {
                    if ($('#grvStudentDetails_dltown_add').val() == "")
                        $('#grvStudentDetails_dltown_add').focus();
                    else
                        $('#grvStudentDetails_txtchannel_add').focus();
                    return false;
                }

            });
            $('#grvStudentDetails_txtchannel_add').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13' || keycode == '108') {
                    if ($('#grvStudentDetails_txtchannel_add').val() == "")
                        $('#grvStudentDetails_txtchannel_add').focus();
                    else
                        $('#grvStudentDetails_txtactive_add').focus();
                    return false;
                }

            });
            $('#grvStudentDetails_txtactive_add').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13' || keycode == '108') {
                   
                    $('#grvStudentDetails_txtngayadd').focus();
                    return false;
                }

            });

            //thuc hien khi list null
            if ($('#grvStudentDetails_btnaddemp').click) {
                $('#grvStudentDetails_txtcustidemp').focus();
            }
            $('#grvStudentDetails_txtcustidemp').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13' || keycode == '108') {
                    if ($('#grvStudentDetails_txtcustidemp').val == "")
                        $('#grvStudentDetails_txtcustidemp').focus();
                    else
                        $('#grvStudentDetails_txtcustnameemp').focus();
                    return false;
                }
            });
            $('#grvStudentDetails_txtcustnameemp').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13' || keycode == '108') {
                    if ($('#grvStudentDetails_txtcustnameemp').val == "")
                        $('#grvStudentDetails_txtcustnameemp').focus();
                    else
                        $('#grvStudentDetails_txtcustaddressemp').focus();
                    return false;
                }

            });
            $('#grvStudentDetails_txtcustaddressemp').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13' || keycode == '108') {
                    if ($('#grvStudentDetails_txtcustaddressemp').val == "")
                        $('#grvStudentDetails_txtcustaddressemp').focus();
                    else
                        $('#grvStudentDetails_dlprovinceemp').focus();
                    return false;
                }

            });
            $('#grvStudentDetails_dlprovinceemp').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13' || keycode == '108') {
                    if ($('#grvStudentDetails_dlprovinceemp').val == "")
                        $('#grvStudentDetails_dlprovinceemp').focus();
                    else
                        $('#grvStudentDetails_dldistemp').focus();
                    return false;
                }

            });
            $('#grvStudentDetails_dldistemp').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13' || keycode == '108') {
                    if ($('#grvStudentDetails_dldistemp').val == "")
                        $('#grvStudentDetails_dldistemp').focus();
                    else
                        $('#grvStudentDetails_txtchanemp').focus();
                    return false;
                }

            });
            $('#grvStudentDetails_txtchanemp').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13' || keycode == '108') {
                    if ($('#grvStudentDetails_txtchanemp').val == "")
                        $('#grvStudentDetails_txtchanemp').focus();
                    else
                        $('#grvStudentDetails_txtactivemp').focus();
                    return false;
                }

            });
            $('#grvStudentDetails_txtactivemp').keypress(function (event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13' || keycode == '108') {
                  
                    $('#grvStudentDetails_txtngay').focus();
                        return false;
                }

            });
        });
    </script>
    <%--  /*chặn nhập chữ*/--%>
    <script type="text/javascript">
        function ValidateKeypress(numcheck, e) {
            var keynum, keychar, numcheck;
            if (window.event) {//IE
                keynum = e.keyCode;
            }
            else if (e.which) {// Netscape/Firefox/Opera
                keynum = e.which;
            }
            if (keynum == 8 || keynum == 127 || keynum == null || keynum == 9 || keynum == 0 || keynum == 13) return true;
            keychar = String.fromCharCode(keynum);
            var result = numcheck.test(keychar);
            return result;
        }
    </script>
      <script>
          $(function () {
              $("#grvStudentDetails_txtngay").datepicker();
          });
  </script>
    <script>
        $(function () {
            $("#grvStudentDetails_txtngayadd").datepicker();
        });
  </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:GridView ID="grvStudentDetails" runat="server"
                ShowFooter="True" AutoGenerateColumns="False"
                CellPadding="4" ForeColor="#333333"
                DataKeyNames="CustID" OnRowCancelingEdit="grvStudentDetails_RowCancelingEdit" OnRowEditing="grvStudentDetails_RowEditing" OnRowDeleting="grvStudentDetails_RowDeleting">
                <EmptyDataTemplate>
                    <table rules="all" style="color: #333333; border-collapse: collapse;" border="1" cellpadding="4" cellspacing="0">
                        <tr style="color: White; background-color: #507CD1; font-weight: bold;">
                            <th scope="col">CustID</th>
                            <th scope="col">CustName</th>
                            <th scope="col">CustAddress</th>
                            <th scope="col">ProvinceCode</th>
                            <th scope="col">TownCode</th>
                            <th scope="col">Channel</th>
                            <th scope="col">Active</th>
                            <th scope="col">Ngày</th>
                            <th>&nbsp;</th>
                        </tr>
                        <tr>
                            <td colspan="9">không có dữ liệu</td>
                        </tr>
                        <tr>
                            <td>
                                <asp:TextBox ID="txtcustidemp" runat="server"></asp:TextBox>
                            </td>
                            <td>
                                <asp:TextBox ID="txtcustnameemp" runat="server"></asp:TextBox>
                            </td>
                            <td>
                                <asp:TextBox ID="txtcustaddressemp" runat="server"></asp:TextBox>
                            </td>
                            <td>
                                <asp:DropDownList ID="dlprovinceemp" runat="server" AutoPostBack="True" OnSelectedIndexChanged="dlprovin_emp_SelectedIndexChanged">
                                </asp:DropDownList>
                            </td>
                            <td>
                                <asp:DropDownList ID="dldistemp" runat="server"></asp:DropDownList>
                            </td>
                            <td>
                                <asp:TextBox ID="txtchanemp" runat="server" onkeypress="return ValidateKeypress(/\d/,event);"></asp:TextBox>
                            </td>
                            <td>
                                <asp:CheckBox ID="txtactivemp" runat="server" name="txtngay" />
                            </td>
                            <td>
                                <asp:TextBox ID="txtngay" runat="server"  ></asp:TextBox>
                                <%--<input type="text" id="txtngay" name="txtngay" runat="server"   placeholder="ngày" readonly="readonly" />--%>
                            </td>
                            <td>

                                <asp:Button ID="btnaddemp" runat="server" Text="Add" OnClick="btnadd_click" />
                            </td>
                        </tr>
                    </table>
                </EmptyDataTemplate>
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:Label ID="lblcustidhead" runat="server" Text="custid"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblcustid" runat="server" Text='<%# Eval("CustID") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtcustid" runat="server" Text='<%# Eval("CustID")%>'></asp:TextBox>
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox ID="txtcust_add" runat="server"></asp:TextBox>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:Label ID="lblcustname_head" runat="server" Text="name"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblcustname" runat="server" Text='<%# Eval("Customername") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtcustname" runat="server" Text='<%# Eval("Customername")%>'></asp:TextBox>
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox ID="txtcustname_add" runat="server"></asp:TextBox>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:Label ID="lbladresshead" runat="server" Text="adress"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lbladdress" runat="server" Text='<%# Eval("Address") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtaddress" runat="server" Text='<%# Eval("Address")%>'></asp:TextBox>
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox ID="txtaddress_add" runat="server"></asp:TextBox>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:Label ID="lblprovinchead" runat="server" Text="province"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblprovince" runat="server" Text='<%# Eval("ProvinceCode") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtprovince" runat="server" Text='<%# Eval("ProvinceCode")%>'></asp:TextBox>
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:DropDownList ID="dlprovince_add" runat="server" AutoPostBack="True" OnSelectedIndexChanged="dlprovince_add_SelectedIndexChanged">
                            </asp:DropDownList>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:Label ID="lbltownhead" runat="server" Text="town"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lbltown" runat="server" Text='<%# Eval("TownCode") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txttown" runat="server" Text='<%# Eval("TownCode")%>'></asp:TextBox>
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:DropDownList ID="dltown_add" runat="server"></asp:DropDownList>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:Label ID="lblchannelhead" runat="server" Text="channel"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblchannel" runat="server" Text='<%# Eval("Channel") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtchannel" runat="server" Text='<%# Eval("Channel")%>' onkeypress="return ValidateKeypress(/\d/,event);"></asp:TextBox>
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox ID="txtchannel_add" runat="server" onkeypress="return ValidateKeypress(/\d/,event);"></asp:TextBox>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:Label ID="lblactivehead" runat="server" Text="active"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblactive" runat="server" Text='<%# Eval("Active") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtactive" runat="server" Text='<%# Eval("Active")%>'></asp:TextBox>
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:CheckBox ID="txtactive_add" runat="server" />
                        </FooterTemplate>
                    </asp:TemplateField>
                     <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:Label ID="lblngayadd" runat="server" Text="Ngày"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblngay" runat="server" Text='<%# Eval("Ngay") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtngayedit" runat="server" Text='<%# Eval("Ngay") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox ID="txtngayadd" runat="server"></asp:TextBox>
                     <%--<input type="text" id="txtngayadd" name="txtngayadd" readonly="readonly" runat="server" placeholder="ngày"  />--%>

                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField ShowHeader="False">
                        <EditItemTemplate>
                            <asp:LinkButton ID="lbupdate" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
                            &nbsp;<asp:LinkButton ID="lbancel" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:LinkButton ID="lbedit" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
                        </ItemTemplate>
                        <FooterTemplate>
                            <asp:Button ID="btnadd" runat="server" Text="Add" OnClick="btnadd_click" />
                        </FooterTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField ShowHeader="False">
                        <ItemTemplate>
                            <asp:LinkButton ID="lbdelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>

                </Columns>
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <RowStyle BackColor="#EFF3FB" />
                <EditRowStyle BackColor="#2461BF" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" />
            </asp:GridView>
        </div>
        <asp:LinkButton ID="lbluu" runat="server" OnClick="LinkButton3_Click">Lưu</asp:LinkButton>
    </form>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#grvStudentDetails_txtcustname_add").autocomplete({
                source: function (request, response) {
                    var param = { towncode: $('#grvStudentDetails_txtcustname_add').val() };
                    $.ajax({
                        url: "DemoGrid.aspx/loadtown",
                        data: JSON.stringify(param),
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        dataFilter: function (data) { return data; },
                        success: function (data) {
                            response($.map(data.d, function (item) {
                                return {
                                    value: item
                                }
                            }))
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(textStatus);
                        }
                    });
                },
                minLength: 1
            });
        });
    </script>
    <script type="text/javascript">
        $(function () {
            $("#grvStudentDetails_txtcustnameemp").autocomplete({
                source: function (request, response) {
                    var param = { towncode: $('#grvStudentDetails_txtcustnameemp').val() };
                    $.ajax({
                        url: "DemoGrid.aspx/loadtown",
                        data: JSON.stringify(param),
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        dataFilter: function (data) { return data; },
                        success: function (data) {
                            response($.map(data.d, function (item) {
                                return {
                                    value: item
                                }
                            }))
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(textStatus);
                        }
                    });
                },
                minLength: 1
            });
        });
    </script>
    <div id="abc" runat="server"></div>
</body>
</html>
